package com.ChengXiZi.controller.user;

import com.ChengXiZi.dto.CommunityAddDTO;
import com.ChengXiZi.dto.UserCommunityAddDTO;
import com.ChengXiZi.result.Result;
import com.ChengXiZi.service.CommunityService;
import com.ChengXiZi.service.UserCommunityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户端-社区接口
 */

@Slf4j
@RestController
@Api(tags = "社区接口")
@RequestMapping("/community")
public class CommunityController {

    @Autowired
    private CommunityService communityService;
    @Autowired
    private UserCommunityService userCommunityService;

    /**
     * 创建社区
     * @param communityAddDTO
     * @return
     */
    @PostMapping("/create")
    @ApiOperation("创建社区")
    public Result create (@RequestBody CommunityAddDTO communityAddDTO) {
        log.info("创建社区：{}",communityAddDTO);
        communityService.create(communityAddDTO);
        return Result.success();
    }

    /**
     * 用户加入社区
     * @param userCommunityAddDTO
     * @return
     */
    @PutMapping
    @ApiOperation("加入社区")
    public Result join(@RequestBody UserCommunityAddDTO userCommunityAddDTO) {
        log.info("用户加入社区：{}",userCommunityAddDTO);
        userCommunityService.join(userCommunityAddDTO);
        return Result.success();
    }

}
